
export function moreLineOpt(data) {
	return {
		color: ['#0091FF', '#37E4EC', '#8D54EE', '#41CE78', '#FFAE38', '#3CA272', '#FC8452', '#9A60B4', '#ea7ccc'],
		fontSize: '10',
		tooltip: {
			trigger: 'axis',
			axisPointer: {
				type: 'line',
				label: {
					backgroundColor: '#6a7985'
				}
			},
			position: function (pos, params, el, elRect, size) {
				var obj = { top: 'auto' };
				obj[['left', 'right'][+(pos[0] < size.viewSize[0] / 2)]] = 30;
				return obj;
			},
			formatter: function (params) {
				var relVal = params[0].name;
				// console.log('moreLineOpt', params,data)
				for (var i = 0, l = params.length; i < l; i++) {
					relVal += '\n' + params[i].marker + params[i].seriesName + '：' + params[i].value + (params[i].componentIndex == 0 ? '小时' : '分钟');
				}
				return relVal;
			}
		},
		legend: {
			// padding: [0, 0, 0, 0],
			// bottom: '10',
			fontSize: '10',
			itemHeight: 10,
			itemWidth: 20,
			textStyle: {
				color: '#666',
				fontSize: '10'
			},
			top: 'bottom',
		},

		grid: {
			top: 30,
			bottom: 50
			// containLabel:true,
		},
		xAxis: [
			{
				lineStyle: {
					type: 'dashed'// 虚线
				},
				axisLine: {
					lineStyle: {
						color: '#999'
					},
				},
				axisTick: {
					inside: true,
					lineStyle: {
						color: '#999'
					}
				},
				axisLabel: {
					textStyle: {
						color: '#999',
					},
					formatter: function (date, index) {
						if (date.indexOf('月') != -1) {
							return date;
						} else {
							if (date.indexOf('~') != -1) {
								// 按周
								let arr = date.split('~');
								try {
									return (arr[0].slice(5) + '~' + arr[1].slice(5));
								} catch (e) {
									// TODO handle the exception
									return date;
								}
							} else {
								return (date.slice(5));
							}
						}
					},
				},
				type: 'category',
				boundaryGap: false,
				data: data.categories
			}
		],
		yAxis: [
			{
				alignTicks: true,
				verticalAlign: 'top',
				name: '小时',
				nameGap: 15,
				nameLocation: 'end',
				nameTextStyle: {
					color: '#999',
					align: 'center'
				},
				type: 'value',
				axisLabel: {// y轴文字的配置
					textStyle: {
						color: '#999',// Y轴内容文字颜色
					},
				},
				splitLine: {
					lineStyle: {
						type: 'dashed',
						color: 'rgba(0,0,0,0.10)',
					},
				},
			},
			{

				alignTicks: true,
				verticalAlign: 'top',
				name: '分钟',
				nameGap: 15,
				nameLocation: 'end',
				position: 'right',
				nameTextStyle: {
					color: '#999',
					align: 'center'
				},
				type: 'value',
				axisLabel: {// y轴文字的配置
					textStyle: {
						color: '#999',// Y轴内容文字颜色
					},
				},
				splitLine: {
					lineStyle: {
						type: 'dashed',
						color: 'rgba(0,0,0,0.10)',
					},
				},
			}
		],
		series: data.data
	};
}

export function onelineOpt(data) {
	return {
		color: ['#0091FF', '#37E4EC', '#8D54EE', '#41CE78', '#FFAE38', '#3CA272', '#FC8452', '#9A60B4', '#ea7ccc'],
		fontSize: '10',
		tooltip: {
			trigger: 'axis',
			axisPointer: {
				type: 'line',
				label: {
					backgroundColor: '#6a7985'
				}
			},
			position: function (pos, params, el, elRect, size) {
				var obj = { top: 'auto' };
				obj[['left', 'right'][+(pos[0] < size.viewSize[0] / 2)]] = 30;
				return obj;
			},
			formatter: function (params) {
				var relVal = params[0].name;
				// console.log('onelineOpt', params,data)
				for (var i = 0, l = params.length; i < l; i++) {
					relVal += '\n' + params[i].marker + params[i].seriesName + '：' + params[i].value + (data.unit ? data.unit : '');
				}
				return relVal;
			}
		},
		legend: {
			// padding: [0, 0, 0, 0],
			// bottom: '10',
			// height:50,
			// backgroundColor:'#ccc',
			fontSize: '10',
			itemHeight: 10,
			itemWidth: 20,
			textStyle: {
				color: '#666',
				fontSize: '10'
			},
			top: 'bottom',
		},

		grid: {
			top: 30,
			bottom: 60
			// containLabel:true,
		},
		xAxis: [
			{

				lineStyle: {
					type: 'dashed'// 虚线
				},
				axisLine: {
					lineStyle: {
						color: '#999'
					},
				},
				axisTick: {
					inside: true,
					lineStyle: {
						color: '#999'
					}
				},
				axisLabel: {
					textStyle: {
						color: '#999',
					},
					formatter: function (date, index) {
						if (date.indexOf('月') != -1) {
							return date;
						} else {
							if (date.indexOf('~') != -1) {
								// 按周
								let arr = date.split('~');
								try {
									return (arr[0].slice(5) + '~' + arr[1].slice(5));
								} catch (e) {
									// TODO handle the exception
									return date;
								}
							} else {
								return (date.slice(5));
							}
						}
					},
				},
				type: 'category',
				boundaryGap: false,
				data: data.categories
			}
		],
		yAxis: [
			{
				alignTicks: true,
				verticalAlign: 'top',
				name: data.unit || '',

				nameGap: 15,
				nameLocation: 'end',
				nameTextStyle: {
					color: '#999',
					align: 'center'
				},
				type: 'value',
				axisLabel: {// y轴文字的配置
					textStyle: {
						color: '#999',// Y轴内容文字颜色
					},
				},
				splitLine: {
					lineStyle: {
						type: 'dashed',
						color: 'rgba(0,0,0,0.10)',
					},
				},
			}
		],
		series: data.data
	};
}

export function setLineOptMore(data) {
	return {
		color: ['#0091FF', '#37E4EC', '#8D54EE', '#41CE78', '#FFAE38', '#3CA272', '#FC8452', '#9A60B4', '#ea7ccc'],

		type: 'line',
		padding: [15, 10, 0, 0],
		dataLabel: false,
		dataPointShape: true,
		enableScroll: false,
		// enableScroll: true,
		xAxis: {
			type: 'dash',
			gridColor: '#e5e5e5',
			gridType: 'dash',
			fontColor: '#999999',
			axisLineColor: '#666',
			// scrollShow: true,
			// itemCount: 4,
			labelCount: 5,
			fontSize: 11
		},
		yAxis: {
			gridType: 'dash',
			gridColor: '#e5e5e5',
			axisLineColor: '#fff',
			fontColor: '#999999',
			min: 0,
			fontSize: 11,
			splitNumber: 5,
			data: [{
				gridType: 'dash',
				gridColor: '#e5e5e5',
				axisLineColor: '#fff',
				fontColor: '#999999',
				min: 0,
				fontSize: 11,
				tofix: 1
			},
			{
				gridType: 'dash',
				gridColor: '#e5e5e5',
				axisLineColor: '#fff',
				fontColor: '#999999',
				position: 'right',
				min: 0,
				fontSize: 11,
				tofix: 0
			}
			]
		},
		legend: {
			itemGap: 15,
			fontColor: '#666666'
		},
		fontColor: '#999999',
		extra: {
			tooltip: {
				showArrow: false,
				labelBgColor: '#ffffff'
			},
			line: {
				type: 'curve',
				width: 2,
				gridType: 'dash'
			}
		}
	};
}
export function setLineOpt(data, types) {
	return {
		color: ['#0091FF', '#37E4EC', '#8D54EE', '#41CE78', '#FFAE38', '#3CA272', '#FC8452', '#9A60B4', '#ea7ccc'],

		type: types ? types : 'area',
		padding: [15, 10, 0, 0],
		dataLabel: false,
		dataPointShape: true,
		enableScroll: false,
		// enableScroll: true,
		xAxis: {
			type: 'dash',
			gridColor: '#e5e5e5',
			gridType: 'dash',
			fontColor: '#999999',
			axisLineColor: '#666',
			labelCount: 5,
			fontSize: 11
		},
		yAxis: {
			gridType: 'dash',
			gridColor: '#e5e5e5',
			axisLineColor: '#fff',
			fontColor: '#999999',
			splitNumber: 5,
			min: 0,
			fontSize: 11,
			hideTofix: true,
			tofix: data && data.tofix ? data.tofix : 0
		},
		legend: {
			itemGap: 15,
			fontColor: '#666666',
			lineHeight: 20,
			fontSize: 11
		},
		fontColor: '#999999',
		extra: {
			tooltip: {
				showArrow: false,
				labelBgColor: '#ffffff'
			},
			line: {
				type: 'curve',
				width: 2,
				gridType: 'dash'
			},
			area: {
				type: 'curve',
				// type: 'straight',
				opacity: 0.2,
				addLine: true,
				width: 2,
				gradient: false
			}
		}
	};
}
export function setBarOpt(datas) {
	return {
		color: ['#6FA9FF', '#87DDE7', '#B59CFE', '#FBCB92', '#FFAE38', '#3CA272', '#FC8452', '#9A60B4', '#ea7ccc'],

		type: 'bar',
		padding: [15, 30, 0, 5],
		dataLabel: false,
		dataPointShape: true,
		enableScroll: false,
		showTitle: true,
		// enableScroll: true,
		xAxis: {
			// gridColor: '#e5e5e5',
			gridType: 'dash',
			// fontColor: '#999999',
			// axisLineColor: '#666',
			// labelCount: 5,
			// fontSize: 11,
			// disableGrid: false,
			// boundaryGap: "justify",
			hideTofix: true,
			min: 0,
			axisLine: true,
			axisLineColor: '#333',
			max: datas.max || 0
		},
		yAxis: {
			disabled: false,
			disableGrid: false,
			splitNumber: 5,
			gridType: 'dash',
			dashLength: 8,
			gridColor: '#CCCCCC',
			padding: 10,
			min: 0,

			showTitle: false,

			// data: []
			data: [{
				// disabled:true,
				type: 'categories',
				axisLineColor: '#333',
				axisLine: true
			}]
		},
		legend: {
			show: false,
			// itemGap:10,
			margin: 5,
			padding: 5
		},
		fontColor: '#999999',

		extra: {
			tooltip: {
				showArrow: false,
				labelBgColor: '#ffffff'
			},

			bar: {
				type: 'stack',
				width: 14,
				meterBorde: 1,
				meterFillColor: '#999',
				activeBgColor: '#fff',
				activeBgOpacity: 0.0,
				categoryGap: 2,
				linearType: 'custom'
				// barBorderCircle: true,
			}
		}
	};
}
export function setRingOpt(opts = {}, name) {
	return {
		color: opts && opts.color ? opts.color : ['#F47D99', '#6FA9FF', '#B59CFE', '#87E7B4', '#DDF474', '#3CA272',
			'#FC8452', '#9A60B4', '#ea7ccc'
		],

		tooltip: {
			trigger: 'item',
			show: false
		},
		legend: {
			show: true,
			orient: 'vertical',
			top: 'center',
			right: '50',
			icon: 'circle',
			itemWidth: 9,
			textStyle: {
				color: '#666',
			}
		},

		series: [
			{
				name: name,
				type: 'pie',
				// radius: ['50%', '90%'],
				radius: opts.type == 'pie' ? '90%' : ['40%', '70%'],
				center: ['90', '50%'],
				label: {
					show: false,
					position: 'center',
					formatter: function (lable) {
						return [
							`{d|${lable.data.value}}{d|%}`,
							`{b|${lable.data.name && lable.data.name.length > 6 ? lable.data.name.slice(0, 5) + '...' : lable.data.name}}`
						].join('\n');
					},

					rich: {
						d: {
							fontSize: '18',
							fontWeight: 'bold',
							lineHeight: '22'
						},
						b: {
							fontSize: '12',
							color: '#999999'
						},

					}
				},
				itemStyle: {
					borderColor: '#fff',
					borderWidth: 2
				},
				emphasis: {
					label: {
						show: opts.type == 'pie' ? false : true,
						// position: 'center',
						color: '#333',
						// fontSize: '30',

					},
				},
				labelLine: {
					show: false
				},
				data: opts.data

			}
		]
	};
}
